package com.news.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.news.bean.Setinfo;
import com.news.dao.SetinfoDao;
import com.news.dao.impl.SetinfoDaoImpl;

public class SetinfoServlet extends HttpServlet {
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		//显示设置信息<现列出setinfo信息然后进行显示>
		Map map = new HashMap();
		Setinfo si = new Setinfo();
		SetinfoDao sd = new SetinfoDaoImpl(); 
		String setinfo = req.getParameter("setinfo");
		System.out.println(setinfo+"******"+"setinfo");
		//String sid = req.getParameter("id");
		//Integer id = (sid == null ? null : Integer.valueOf(sid));
		String title = req.getParameter("title");
		//System.out.println("title"+"***"+title);
		String keyword = req.getParameter("keyword");
		String setauth = req.getParameter("setauth");
		si.setTitle(title);
		si.setKeyword(keyword);
		si.setSetauth(setauth);
		
		if(setinfo.equals("show")){	//显示列表
			//System.out.println(setinfo.equals("show"));
				List<Setinfo> list = sd.getSetinfoList(map);
				req.setAttribute("list", list);
				req.getRequestDispatcher("siteinfo.jsp").forward(req, resp);
		}if(setinfo.equals("setauth")){	//设置信息
				sd.setinfo(si);
				//System.out.println(sd.setinfo(si));
				//req.getSession().getAttribute("");
				resp.sendRedirect("setinfo?setinfo=show");
		}
			
	}
		
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
